﻿
using System.Collections;


int num = 0;
while(true)
{
    Console.WriteLine("请输入一个正整数");
    string str = Console.ReadLine();
    num = Convert.ToInt32(str);
    if (num > 0) 
        break;
    else
        Console.WriteLine("数据非法，请重新输入");
}
int endSign = num / 2;
//计算2到endsign之间的所有素数因子
int j = 2;
ArrayList prime = new ArrayList();
while (j <= endSign)
{
    bool flag = true;
    int index = 2;
    while (index < j)
    {
        int a = j % index;
        if (a == 0)
        {
            flag = false;
            break;
        }
        else
            index++;
    }
    if (flag)//是素数
    {
        prime.Add(j);
    }
    j++;
}
ArrayList result = new ArrayList();
while(num != 1)
{
    foreach (int i in prime)
    {
        int testNum = num% i;
        if (testNum == 0)
        {
            num = num / i;
            result.Add(i);
        }
        
    }
}
Console.WriteLine("素数因子为：");
foreach (int i in result)
    Console.Write(i + " ");

